<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>表单提交</title>
    <style>
        .error {
            color: red;
        }
    </style>
</head>
<body>
<h1>提交评论和内容</h1>
<!-- 去掉 th:object，通过隐藏 input 分别绑定对象 -->
<form th:action="@{/submit}" method="post" enctype="multipart/form-data" th:object="${content}">

<h2>内容信息</h2>
    <label for="content">内容:</label>
    <input type="text" id="content" th:field="*{content}">
    <span class="error" th:if="${#fields.hasErrors('content')}" th:errors="*{content}"></span><br>

    <label for="image">图片:</label>
    <input type="file" id="image" th:field="*{image}" name="image"><br>
    <!-- 确保文件输入框正确绑定 -->
    <span class="error" th:if="${#fields.hasErrors('image')}" th:errors="*{image}"></span><br>

    <label for="likes">点赞数:</label>
    <input type="number" id="likes" th:field="*{likes}">
    <span class="error" th:if="${#fields.hasErrors('likes')}" th:errors="*{likes}"></span><br>

    <label for="time">时间:</label>
    <input type="text" id="time" th:field="*{time}">
    <span class="error" th:if="${#fields.hasErrors('time')}" th:errors="*{time}"></span><br>

    <h2>评论信息</h2>
    <label for="comment">评论内容:</label>
    <input type="text" id="comment" th:field="*{comment}">
    <span class="error" th:if="${#fields.hasErrors('comment')}" th:errors="*{comment}"></span><br>

    <label for="commentTime">评论时间:</label>
    <input type="text" id="commentTime" th:field="*{commentTime}">
    <span class="error" th:if="${#fields.hasErrors('commentTime')}" th:errors="*{commentTime}"></span><br>

    <label for="commentLike">点赞数:</label>
    <input type="number" id="commentLike" th:field="*{commentLike}">
    <span class="error" th:if="${#fields.hasErrors('commentLike')}" th:errors="*{commentLike}"></span><br>

    <input type="submit" value="确定">
</form>
</body>
</html>